package com.ruoyi.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.admin.domain.UserB01;
import com.ruoyi.admin.mapper.UserB01Mapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
@AllArgsConstructor
public class B01Service implements IB01Service {

    private UserB01Mapper userB01Mapper;


    @Override
    public Set<String> selectUserB01ByUserId(Long userId) {
        LambdaQueryWrapper<UserB01> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserB01::getUserId, userId);
        List<UserB01> userB01s = userB01Mapper.selectList(queryWrapper);
        Set<String> b01s = new HashSet<>();
        for (UserB01 userB01 : userB01s) {
            if (StringUtils.isNotBlank(userB01.getB0111())) {
                b01s.add(userB01.getB0111());
            }
        }
        return b01s;
    }

    @Override
    public AjaxResult createUserB01(Long userId, String b0111) {
        UserB01 userB01 = new UserB01();
        userB01.setUserId(userId);
        userB01.setB0111(b0111);
        int insert = userB01Mapper.insert(userB01);
        if (insert > 0) {
            return AjaxResult.success("添加成功");
        }
        return AjaxResult.error("添加失败");
    }
}
